<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\Draw as DrawModel;
use app\common\tool\Result;
use think\facade\View;
use think\Response;
use think\response\Json;
use app\common\model\Message as MessageModel;
use think\exception\ValidateException;

class Message extends Base
{

    /**
     * 提交投诉建议
     * @return Response
     */
    public function save() :Response
    {
        $param = $this->request->post('', '', $this->filter);
        try {
            $this->validate($param, 'Message');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }

        $result = MessageModel::add($param, $this->user);

        return Result::fastReturn($result);
    }

    /**
     * 我的投诉建议
     * @return Response
     */
    public function index() :Response
    {
        $map = ['uid' => $this->user->id, 'is_del' => 0];

        return Result::fastReturn(MessageModel::getPageList($map, 'id,uid,status,images,comment,rcomment,create_time,read_time,reply_time', $this->getPage(), $this->getLimit(), false));
    }

}

